草庐IT

Python Django 模板 : Iterate Through List

全部标签

c++ - 以函数作为模板参数的偏特化拒绝

得到这段代码,以前的gcc版本可以很好地编译:templatestructHelperWrapper;//[...]templatestructHelperWrapper{staticinlineintWrapFuncT(constint){return0;//Changed}};//UnarytemplatestructHelperWrapper{staticinlineintWrapFuncT(constint){return1;//Changed}};//BinarytemplatestructHelperWrapper{staticinlineintWrapFuncT(cons

C++ 模板特化不适用于嵌套类型

以下代码可以编译,但无法运行:templatestructNesting{templatestruct_Nested{};templateusingNested=_Nested;};templatestructF{staticconstexprboolis_my_nested_class=false;};templatestructF::Nested>{staticconstexprboolis_my_nested_class=true;};我创建了这些Nesting和Nested类型,并尝试在其上使用类型特征模式。它编译(使用MSVC2014w/CPP11),但是F::Nested>

c++ - 使用 boost 预处理实例化模板函数和类

使用看似标准的w,x,y,z演示,假设我有以下宏试图转换为“可迭代”预处理器宏#defineINSTANTIATE_FUNC(rtype,func_name,...)\templatertypefunc_name(__VA_ARGS__);\templatertypefunc_name(__VA_ARGS__);\templatertypefunc_name(__VA_ARGS__);\templatertypefunc_name(__VA_ARGS__);为了完整起见,假设我们正在尝试实例化以下内容structw{staticconstexprintdata=0;};structx{

c++ - 具有非类型参数包的模棱两可的类模板实例化

我试图专门化Expr:#include#include#includetemplatestructExpr{Expr(){std::coutstructExpr...>>{Expr(){std::coutstructExpr...>>{Expr(){std::cout>mylist;Exprtest{};return0;}但是,我遇到了以下编译器错误:[x86-64gcc6.3]error:ambiguoustemplateinstantiationfor'structExpr>>'[x86-64gcc6.3]error:variable'Expr>>test'hasinitializ

c++ - 在 C++ 接口(interface)中声明模板函数?

为了演示,假设我有一些动物类,每个都派生自“动物”类,每个都“知道”它们是什么类型,并且每个都具有某种独特的能力:enumclassanimal_type{antelope,bear,cat};classanimal{};classantelope:publicanimal{public:staticconstanimal_typetype=animal_type::antelope;voidrun(){std::cout现在,我希望能够根据动物的类型检索动物:classanimal_getter{public:animal&get(animal_typet){staticantelo

C++ 模板元编程 : how to deduce type in expression pattern

我想要静态检查lambda的参数类型。我在下面编写了这段代码,它似乎产生了正确的结果。structB{};autolamBc=[](Bconst&b){std::coutconstexprautoArgType(R(ClosureType::*)(Arg)const)->Arg;templateusingArgType_t=decltype(ArgType(&T::operator()));//ArgType_tis"referencetoBconst"但是,我注意到,例如,标准库使用类模板特化从std::remove_reference中的引用类型中提取引用类型。所以我尝试了这种方法

c++ - 匿名命名空间中模板化类的友元

声明类时A作为类(class)的friendB,而A在匿名命名空间和B中定义在外部,一些编译器会产生错误“protectedmemberinaccessible”,而其他编译器不会产生任何错误或警告。如果A或B或者两者都是模板:namespace{templatestructA{templatevoidfoo(BBconst&b){b.bar();}};}//endanonymousnamespacetemplateclassB{templatefriendstructA;protected:voidbar()const{}};intmain(){Aa;a.foo(B{});}A和B都

属于模板类的成员模板的 C++ 显式特化

在目前的C++标准草案中,thisparagraph中就有这个例子属于与模板的显式特化相关的部分:templatestructA{voidf(T);templatevoidg1(T,X1);templatevoidg2(T,X2);voidh(T){}};//specializationtemplatevoidA::f(int);//outofclassmembertemplatedefinitiontemplatetemplatevoidA::g1(T,X1){}//membertemplatespecializationtemplatetemplatevoidA::g1(int,X

使用命名空间时,C++ 模板函数无法使用 g++ 进行编译

下面的代码编译得很好:(没有命名空间)#includetemplatevoidfoo(constint&from,std::vector&to){for(inti=0;ibars;};voidfoo(constint&from,Bar&to){to.a=from;to.b=from-1;}voidfoo(constint&from,Baz&to){foo(from,to.bars);}voidfooTest(){intnum=10;Bazbaz;foo(num,baz);}intmain(){fooTest();}但是当我为Bar和Baz引入命名空间时,它无法编译。(带命名空间)#in

c++ - 无模板优化

我正在编写一个国际象棋引擎,我有一个如下所示的函数:U64find_moves(Piecetype,Teamside,uint8_tsquare,U64occupied){switch(type){casePAWN:{U64result=0;result|=occupied&bb_normal_moves::pawn_caps[side][square];if(!(occupied&bb_normal_moves::pawn_moves_x1[side][square])){result|=bb_normal_moves::pawn_moves_x1[side][square];if(